//
//  Utils.m
//  LibWeexDCFileTransfer
//
//  Created by simple on 2019/4/18.
//  Copyright © 2019年 simple. All rights reserved.
//

#import "Utils.h"

@implementation Utils

//文件存储目录
+ (NSString *)newDirector{
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
//        NSString *path = [paths objectAtIndex:0];
    
//    NSString *paths =  NSTemporaryDirectory();
    
    NSString *path = [paths lastObject];//[paths objectAtIndex:0];
    path = [path stringByAppendingPathComponent:@"/Pandora/downloads"];
//    NSString *filePath = [path stringByAppendingPathComponent:@"file"];
    return path;
}

+ (NSArray*)listDirectory{
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];//[paths objectAtIndex:0];
    path = [path stringByAppendingPathComponent:@"/Pandora/downloads"];
    
    NSError *error = nil;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *fileList = [fileManager contentsOfDirectoryAtPath:path error:&error];
    NSMutableArray *dirArray = [[NSMutableArray alloc] init];
    BOOL isDir = TRUE;
    //在上面那段程序中获得的fileList中列出文件夹名
    for (NSString *file in fileList) {
        NSString *filePath = [[Utils newDirector] stringByAppendingPathComponent:file];
        [fileManager fileExistsAtPath:filePath isDirectory:(&isDir)];
        if (!isDir) {
            [dirArray addObject:filePath];
        }
        isDir = TRUE;
        
    }
    return dirArray;
}
@end
